package com.salmon.security.core.authorization.impl;

import com.salmon.security.core.authorization.AuthorizeConfigProvider;
import com.salmon.security.core.properties.SecurityProperties;
import com.salmon.security.core.validate.code.SecurityConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.stereotype.Component;

@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class SalmonAuthorizeConfigProvider implements AuthorizeConfigProvider {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    public void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) {
        config.antMatchers(
                SecurityConstants.DEFAULT_UNAUTHENTICATION_URL,
                SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_MOBILE,
                SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_SOCIAL,//社交登录请求地址
                securityProperties.getBrowser().getLoginPage(),//登录地址
                SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX+"/*",//验证码相关
                securityProperties.getBrowser().getSignUpUrl(), // 此配置来处理社交登录成功的回调地址
                securityProperties.getBrowser().getSession().getSessionInvalidUrl(),
                securityProperties.getBrowser().getSignOutUrl() // 注销地址
                )
                .permitAll();
    }
}
